package com.map.controller;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import com.map.domain.Tree;
import com.map.domain.Node;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

@Controller
public class TreeController {
	@RequestMapping(value = "/treedata", method = { RequestMethod.GET,
			RequestMethod.POST })
	public @ResponseBody
	Node Treedata(Model model) throws IOException {
		BufferedReader br= new BufferedReader(new FileReader("treeURL.txt"));
		Tree tree = new Tree(new Node("root"));
		String url=null;
		while((url=br.readLine())!=null)
		{
			
			if(url.indexOf("www.")!=-1)
				url=url.substring(url.indexOf("www.")+4);
			System.out.println(url);
			String[] list = url.split("\\.");
			
			tree.addNode(list);
		}

	    br.close();
	return tree.getRoot();
	}
	
	@RequestMapping(value = "/treemap", method = RequestMethod.GET)
	public void tree(Model model) { 

	}
}
